package com.cqc.jdk8.Jutil.stream;

import com.cqc.eb.UserEB;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cui
 * @date 2024/6/30 12:13
 * @description
 **/
public class LimitTest {


    List<UserEB> userEBList = null;

    @Before
    public void before() {
        userEBList = getUserEBList();
    }

    @Test
    public void limit() {
        userEBList.stream()
                .filter(user -> user.getAge() > 20)
                .limit(1)
                .forEach(System.out::println);
    }

    private List<UserEB> getUserEBList() {
        userEBList = new ArrayList<>();
        userEBList.add(new UserEB("刘诗诗", 15));
        userEBList.add(new UserEB("刘亦菲", 33));
        userEBList.add(new UserEB("古力娜扎", 30));
        userEBList.add(new UserEB("陈都灵", 29));
        userEBList.add(new UserEB("杨紫", 28));
        userEBList.add(new UserEB("林青霞", 60));
        return userEBList;
    }
}
